<template>
  <div :class="{'theme-market': showMarketingBar}">
    <section class="c-maxh440 c-text-hidden c-p">
      <img class="c-w100" :src="$addXossFilter(testInfo.avatar, require('../../../assets/defult270.png'))" alt="" />
      <div class="c-pa c-p-b0 c-w100 c-pv10 c-translucent-balck60 c-fs20 c-fc-white c-ph24" v-if="testInfo.enableLimitTestTime">考试时间:{{testInfo.testStartTime}} - {{testInfo.testEndTime}}</div>
    </section>
    <!-- 营销活动倒计时 -->
    <flash-sales-time-new v-if="showMarketingBar"
      :type="testInfo.sales? 'isSale':testInfo.isFriendHelper ? 'isFa' : 'isCollage'"
      :price="testInfo.sales ? testInfo.sales.price : testInfo.collage ? testInfo.collage.captainPrice : ''"
      :from="testInfo.collage && testInfo.collage.collageGroupType && testInfo.collage.collageGroupType == 2 ? 'activity' : ''"
      :startTime="testInfo.sales ? testInfo.sales.sales.startTime : testInfo.collage ? testInfo.collage.startTime : testInfo.faStartAt"
      :endTime="testInfo.sales ? testInfo.sales.sales.endTime : testInfo.collage ? testInfo.collage.endTime : testInfo.faEndAt"
      :originalPrice="testInfo.price"
      :stock="testInfo.sales ? testInfo.sales.balance: ''"
      :isLimit="testInfo.sales && testInfo.sales.limit == 0 ? false : true"
      :salesTag="testInfo.sales && testInfo.sales.sales.tags"
      :peopleNum="testInfo.collage && testInfo.collage.peopleNum"
      :optimal="optimal"
      @showCoupon="showCoupon = true"
      @falshSalesTime="falshSalesTime"
      @finishFlashSales="finishFlashSales"
    >
    </flash-sales-time-new>
    <section class="c-bd-b12-f5">
      <div class="c-pr24 c-flex-row c-justify-sb c-aligni-center c-pt20" v-if="(testInfo.isSaleAlone==1)&&!(testInfo.sales||testInfo.isFriendHelper)&&!isMarketing&& testInfo.permission == 0">
        <price-bar class="c-ph0"
          :dataInfo="testInfo"
          :styleType="2"
        >
        </price-bar>
      </div>
      <discount-info class="c-mt8" v-if="!distributionId && !isiOS && !testInfo.permission && testInfo.isSaleAlone == 1 && testInfo.payType == 2"
        :couponList="couponList"
        :dataInfo="testInfo"
        :isMarketing="isMarketing"
        @clickShowCoupon="showCoupon = true"
      >
      </discount-info>
      <vip-entry class="c-ph24 c-mt20"
        :styleType="2"
        :dataInfo="testInfo"
        v-if="!testInfo.permission && !$isWxAppIos() && !isiOS && !isMarketing"
      ></vip-entry>
      <div class="c-flex-row c-aligni-center c-box c-ph24 c-pt20">
        <span class="c-fs30 c-fw-b c-fc-xblack">{{testInfo.name}}</span>
      </div>
      <div class="c-fc-gray c-ph24 c-fs22 c-pt20 c-flex-row">
        <span class="c-fs22 c-fc-gray c-pb20"><i class="iconfont c-fs20 c-mr8">&#xe647;</i>{{testInfo.joinNumber}}人参与</span>
      </div>
      <div class="c-ph24 c-bd-t12-f5 c-pv30">
        <div class="c-fs26 c-fc-xblack c-fw-b">考试信息</div>
        <div class="c-flex-row c-aligni-center c-pt30">
          <div class="c-ww210 c-textAlign-c">
            <div class="c-fs22 c-fc-gray">时长(分钟)</div>
            <div class="c-fs26 c-fc-xblack c-mt6 c-fw600">{{testInfo.enableLimitTime==-1?'不限':testInfo.enableLimitTime==2?testInfo.totalTime:'--'}}</div>
          </div>
          <div class="c-line"></div>
          <div class="c-ww210 c-textAlign-c">
            <div class="c-fs22 c-fc-gray">题目量</div>
            <div class="c-fs26 c-fc-xblack c-mt6 c-fw600">{{testInfo.hasAns}}</div>
          </div>
          <div class="c-line"></div>
          <div class="c-ww210 c-textAlign-c">
            <div class="c-fs22 c-fc-gray">考试总分</div>
            <div class="c-fs26 c-fc-xblack c-mt6 c-fw600">{{testInfo.totalScore}}</div>
          </div>
        </div>
      </div>
      <!-- 非强制表单入口 -->
      <formEntry v-if="testInfo.permission && ((testInfo.collectPage==3&& testInfo.isRelForm == true && testInfo.hasFormLog == false && isShowFormlg)||(testInfo.hasFormLog&&testInfo.enableEdit==2&& isShowFormlg&& testInfo.isRelForm == true))"
        relType="11"  :relId="testId"  :dataInfo="testInfo"
        classObject="c-fs22" fontSizeClass="c-fs20" iconSizeClass="c-fs14" topClass="c-bd-t12-f5"
        @goForm="goForm" ></formEntry>
    </section>
    <h2 class="c-ph24 c-fw-n c-fc-xblack c-fs26 c-fw-b c-pt42" v-if="testInfo.details != ''">考试详情</h2>
    <div class="c-mt28 c-pb20 c-fc-sblack c-fs26" v-if="(testInfo && testInfo.combos && testInfo.combos.length > 0)||testInfo.details != ''">
      <div @click="clickDesc" v-if="testInfo.details != ''" class="tinymce-text c-ww-bw c-ww-ba c-contexty-scroll c-ph24" :class="[cfg.isCopyPicture == 0 ? 'closeBig' : 'aCloseBig', cfg.isCopy == 0 ? 'copyNot' : '']" v-html="testInfo.details"></div>
      <loading-status-tem v-if="testInfo.details != ''" :noData="testInfo.details == ''" :noDataText="'暂无内容'"></loading-status-tem>
      <package-index-com :styleType="2"
        @clickGoAllPackage="showCombo=true"
        :relevantTitles="'包含该考试的课程'"
        :isExam='cfrom.testpPaper' :showAll="true"
        :proType="9" :proId="libraryId"
        :isHomePage="false"
        :showPackageModal="true"
        :packageList="testInfo.combos.filter((item,index) => {return index == 0})"
        v-if="testInfo && testInfo.combos && testInfo.combos.length > 0"></package-index-com>
      <!-- <div class="c-ph24 c-pt40 c-pb24" v-if="testInfo&&testInfo.combos&&testInfo.combos.length>0">
        <div class="c-flex-row c-justify-sb">
          <h2 class="c-fw-n c-fc-xblack c-fs26 c-fw-b">配套课程<span class="c-fs20 theme-fc c-pl20">购买所属的课程后可参与考试</span></h2>
          <span class="c-fs20 c-fc-gray" @click="clickGoAllPackage">查看全部</span>
        </div>
        <div class="c-flex-row" :class="index == 0 ? 'c-mt24':'c-mt40'" v-for="(item,index) in testInfo.combos" :key="index" @click="clickGoPackageOrColumn(item)">
          <div class="c-ww150 c-maxh100 c-text-hidden">
            <img class="c-w100 imgCloseBig c-br6" :src="$addXossFilter(item.cover, require('../../../assets/defult270.png'))" />
          </div>
          <div class="c-pl20 c-w0 c-flex-grow1 c-flex-column c-justify-sb">
            <div class="c-fs24 c-text-ellipsis2">{{item.name}}</div>
            <div class="c-flex-row c-aligni-center c-justify-sb">
              <div class="c-fs18 c-fc-gray">类型：{{item.type==1?"知识套餐":item.type==2?"专栏":item.type==3?'测评':item.type==4?'训练营':'课程'}}</div>
              <div class="c-fs18 c-fc-gray" v-if="item.payType == 2&&item.type!=5">{{item.sales}}{{ !$isWxAppIos() ? '人已购买' : '人学习' }}</div>
              <div class="c-fs18 c-fc-gray" v-else>{{item.type==1||item.type==2?item.clicks:item.sales}}{{item.type==4?'人学习':item.type==3?'人测试':'次观看'}}</div>
            </div>
          </div>
        </div>
      </div> -->
    </div>
    <bottom-buy-com
      :ckFrom="125"
      :isNeedPay="!testInfo.permission && ((testInfo.isSaleAlone == 1 && testInfo.payType == 2) || (testInfo.isSaleAlone != 1 && testInfo.isSaleTogether == 1))"
      :showInvitionCard="false"
      :showMarketingCard="testInfo.isFriendHelper || (testInfo.collage && (testInfo.collage.status == 2 || testInfo.collage.status == 1)) || testInfo.sales"
      :showFriendHelper="testInfo.permission == 0 && companyAuth.enableFriendHelper == 1 && testInfo.isFriendHelper"
      :friendHelperStatus="faStatus"
      :showBuyButton="testInfo.payType != 3 && testInfo.status != 3 && testInfo.permission == 0 && testInfo.payType == 2"
      @spreadInvite="spreadInvite"
      @invitePoster="invitePoster"
      @goHelpDetail="goHelpDetail"
      @backPackage="backPackage"
      :showFormText="0"
    >
      <div v-if="testInfo.permission&&testInfo.finishedTestInfo" @click="goAnswerResult" class="c-flex-grow1 c-fs28 theme-fc theme-bd1 c-br36 c-hh64 c-flex-row c-justify-center c-aligni-center c-mr20">
        <div>查看成绩</div>
      </div>
      <div class="c-hh64 c-flex-grow1 c-fs28" v-if="testInfo.isSaleAlone==1&&
        ((!testInfo.permission && testInfo.payType == 2)||
          (testInfo.permission&&(!testInfo.finishedTestInfo||testInfo.enableResurvey==1))||
          (testInfo.permission == false && testInfo.payType == 3))">
        <!-- 付费 -->
        <div v-if="!testInfo.permission && testInfo.payType == 2" class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36" :class="showMarketingBar ? 'theme-bg-gradient' : 'theme-bg'" @click="clickBuy()">{{getBuyBtnTitle}}</div>
        <!-- 有权限 -->
        <div v-if="(testInfo.permission&&!testInfo.finishedTestInfo)||(testInfo.permission&&testInfo.enableResurvey==1)" class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 theme-bg" @click="goTest">
          {{testInfo.enableResurvey==1&&testInfo.finishedTestInfo?'再次考试':'立即测试'}}
        </div>
        <!-- 加密 -->
        <div @click="inputPsw" v-if="testInfo.permission == false && testInfo.payType == 3" class="c-fc-white theme-bg c-br36 c-h c-flex-row c-flex-center">输入密码</div>
      </div>
      <div class="c-hh64 c-flex-grow1 c-fs28" v-if="testInfo.isSaleAlone==-1&testInfo.isSaleTogether==1&&
        (testInfo.permission == false||(testInfo.permission&&!testInfo.finishedTestInfo)||(testInfo.permission&&testInfo.enableResurvey==1))">
        <div v-if="testInfo.permission == false " class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 theme-bg" @click="showCombo=true">立即购买</div>
        <div v-if="(testInfo.permission&&!testInfo.finishedTestInfo)||(testInfo.permission&&testInfo.enableResurvey==1)" class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 theme-bg" @click="goTest">
          {{testInfo.enableResurvey==1&&testInfo.finishedTestInfo?'再次考试':'立即测试'}}
        </div>
      </div>
    </bottom-buy-com>
    <coupon-list-com
      @closeModal="closeModal"
      @getCouponList="getCouponList"
      :couponIsPage="couponIsPage"
      :couponLoading="couponLoading"
      :couponList="couponList"
      :showCoupon="showCoupon"
      :prodId="Number(testId)"
      :prodType="125"
      :sales="testInfo.sales"
      :isMarketing="isMarketing"
      :dataInfo="testInfo"
    >
    </coupon-list-com>
    <comfirm-com :pwTip="''" :showPassword="showPassword" :noticeText="noticeText" :text="'请输入密码进入测试'" :placeholderText="'请输入密码'" @changePsw="changePsw" @closePassword="showPassword = false" @submitPassword="submitPassword"></comfirm-com>
    <share-masker :isShowShare="isShowShare" v-if="isShowShare" @closeShare="isShowShare=false;"></share-masker>
    <!-- 关联弹窗 -->
    <combo-related-list :tittle="'包含该考试的课程'" :minTittle="'购买所属的课程后可参与考试'" :packageList="packageList" @closeCombo="closeCombo" :showCombo="showCombo"></combo-related-list>
  </div>
</template>
<script>
import loadingStatusTem from "@/components/templates/common/loadingStatusTem.vue";
import shareMasker from "@/components/templates/common/shareMasker.vue";
import PackageIndexCom from "@/components/templates/packageIndexCom.vue";
import ComfirmCom from "@/components/templates/common/comfirmCom.vue";
import couponListCom from "@/components/templates/couponListCom.vue";
import { utilJs, wxUtilJs } from "@/utils/common.js";
import bottomBuyCom from "@/components/templates/common/bottomBuyCom.vue";
import FlashSalesTimeNew from "@/components/templates/flashSalesTimeNew.vue";
import PriceBar from '@/components/templates/common/priceBar.vue';
import { getBindPhoneSetting } from "@/utils/checkUnBindPhone.js";
import ComboRelatedList from "@/components/templates/common/comboRelatedList.vue";
import DiscountInfo from "@/components/templates/common/discountInfo.vue";
import VipEntry from "@/components/templates/common/vipEntry.vue";
import formEntry from "@/components/homePage/form/formEntry.vue"
// let testId = "";
let isClick = false;
let pathFrom = '';
export default {
  name: "ClassDetail",
  components: {
    DiscountInfo,
    VipEntry,
    shareMasker,
    PackageIndexCom,
    ComfirmCom,
    couponListCom,
    bottomBuyCom,
    loadingStatusTem,
    FlashSalesTimeNew,
    PriceBar,
    ComboRelatedList,
    formEntry
  },
  data() {
    return {
      companyAuth: JSON.parse(localStorage.getItem("companyAuth")),
      theme: localStorage.getItem("colorName") ? localStorage.getItem("colorName") : "mb5_default",
      testInfo: {
        combos:[]
      }, //permission是否有权限
      vipType: localStorage.getItem("vipType" + localStorage.getItem("userId")),
      vipFitstItem: localStorage.getItem("vipArr1") ? JSON.parse(localStorage.getItem("vipArr1")) : null,
      svipFitstItem: localStorage.getItem("svipArr1") ? JSON.parse(localStorage.getItem("svipArr1")) : null,
      isShowFormlg:localStorage.getItem("showForm") == 1 ? true : false,
      cfg: JSON.parse(localStorage.getItem("cfg")),
      isiOS: false,
      faStatus: 1,
      cfrom:global.ckFrom,
      couponLoading: false,
      couponList: [],
      couponIsPage: false,
      couponPage: 1,
      showCoupon: false,
      isSalesBegin: false, // 判断限时购是否正在进行
      ttId: "",
      tpId: "",
      tlId: "",
      progress: "",
      ckFrom: '',
      testId: '',
      packageList: [],
      examList:[],
      TrainList:[],
      CourseList:[],
      ColumnList:[],
      showPassword: false, //显示密码输入
      noticeText: '',
      isShowShare: false, //目前分享邀请功能未有
      showCombo:false,
      belongLoading:false,
      belongEximLoading:false,
      belongTrainLoading:false,
      CourseListLoading:false,
      ColumnListLoading:false,
      is_page_package: false,
      pagePackage:1,
      pageExim:1,
      pageTrain:1,
      pageCourse:1,
      showActivityTip:false,
      dataStatus:'HAS_MORE_DATA',
      trainDataStatus:'HAS_MORE_DATA',
      CourseListStatus:'HAS_MORE_DATA',
      ColumnListStatus:'HAS_MORE_DATA',
      origin:'', //关联入口来源
      prodId:'', //来源id
      bindPhoneSetting: null,
      themeId: '', //来源圈子任务的主题id
      optimal: null, // 最低价格对象
    };
  },
  created() {
    utilJs.appShare(this);
    let reIdArr = window.location.href.split("testId=");
    if (reIdArr.length > 1 && reIdArr[1]) {
      let rId = reIdArr[1].split("&").length > 0 ? reIdArr[1].split("&")[0] : reIdArr[1];
      window.localStorage.setItem("testId", rId);
    }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      pathFrom = from.path;
    });
  },
  beforeRouteUpdate(to, from, next) {
    if (to.path === from.path) {
      window.location.reload(true)
    }
  },
  mounted() {},
  computed: {
    showMarketingBar() {
      return this.testInfo &&
        (
          this.testInfo.sales ||
          (this.testInfo.collage && (this.testInfo.collage.status == 2 || this.testInfo.collage.status == 1)) ||
          this.testInfo.isFriendHelper
        )
    },
    // 获取按钮专享价名称
    getBuyBtnTitle() {
      if (this.testInfo.sales && this.optimal && this.optimal.optimalPriceType != 101) {
        const agentName = utilJs.getCustNameMap();
        let btnTxt = this.vipType != 1 ? (this.vipType == 2 ? 'VIP专享价' : this.vipType == 4 ? 'SVIP专享价' : agentName[this.vipType] + '专享价') : '立即购买';
        if (this.testInfo.sales && this.optimal.optimalPriceType == 101) {
          btnTxt = '立即购买';
        }
        return btnTxt
      }
      return '立即购买'
    },
    //单卖&&没有权限&&价格大于0&&（加入形式&&不是好友助力）&&（优惠券||vip svip折扣信息||积分抵扣）&&（是否参与营销）
    showDiscount() {
      let showdiscount = this.testInfo.isSaleAlone != 0 && this.testInfo.permission == 0 && Number(this.testInfo.price) > 0 && !this.testInfo.isFriendHelper
      return showdiscount
    },
    //是否是营销活动
    isMarketing() {
      let isMarketing = this.testInfo && (this.testInfo.sales || (this.testInfo.collage && (this.testInfo.collage.status == 2 || this.testInfo.collage.status == 1)) || this.testInfo.isFriendHelper)
      return isMarketing
    },
    //拼团、限时购展示优惠券
    isFavourable() {
      let isFavourable = this.testInfo && this.testInfo.isFriendHelper
      return isFavourable
    },
    //大转盘是否显示
    showTurn() {
      let showturn = this.testInfo.joinActivityInfo && this.testInfo.joinActivityInfo.isJoinActivity == 1
      return showturn;
    }
  },
  watch: {},
  methods: {
    clickGoAllPackage() {
       this.$routerGo(this, "push", {
        path: "/homePage/testPaper/testPackageList",
        query: { testId: this.testId }
      });
    },
    clickGoPackageOrColumn(item) {
      if (item.type == 1) {
        let toPath = `/homePage/package/packageDetail?combosId=${item.cId}`;
        this.$routerGo(this, "push", { path: toPath });
      } else if (item.type == 2) {
        let toPath = `/homePage/column/columnDetail?cId=-1&ckFrom=${global.ckFrom.column}&extId=${item.columnId}`;
        this.$routerGo(this, "push", { path: toPath });
      } else if (item.type == 3) {
        let toPath = `/homePage/examination/examinationDetail?ExaminationNo=${item.topicId}`;
        this.$routerGo(this, "push", { path: toPath });
      } else if (item.type == 4) {
        let toPath = `/homePage/camp/campDetail?campId=${item.id}`;
       this.$routerGo(this, "push", { path: toPath });
      } else if (item.type == 5) {
        let toPath = item.courseType == 1 ?
        `/homePage/course/voice?courseId=${item.courseId}&extId=-1&ckFrom=5` :
        item.courseType == 0 ?
        `/homePage/course/video?courseId=${item.courseId}&extId=-1&ckFrom=5` :
        `/homePage/course/imgText?courseId=${item.courseId}&extId=-1&ckFrom=5`
        ;
        this.$routerGo(this, "push", { path: toPath });
      }
    },
    //记录关联来源
    originModal() {
      utilJs.postMethod(global.apiurl + "paper/entryRecord", {
        paperMainId: this.testId,
        prodId: this.prodId,
        prodType: this.origin
      }, res => {})
    },
    clickCourseItem(CourseItem) {
      let toPath = CourseItem.courseType == 1 ?
        `/homePage/course/voice?courseId=${CourseItem.courseId}&extId=-1&ckFrom=5` :
        CourseItem.courseType == 0 ?
        `/homePage/course/video?courseId=${CourseItem.courseId}&extId=-1&ckFrom=5` :
        `/homePage/course/imgText?courseId=${CourseItem.courseId}&extId=-1&ckFrom=5`
        ;
      this.$routerGo(this, "push", { path: toPath });
    },
    clickColumnItem(ColumnItem) {
      this.$routerGo(this, "push", {
        path: "/homePage/column/columnDetail",
        query: { cId:-1, ckFrom:global.ckFrom.column, extId: ColumnItem.columnId }
      });
    },
    clickPackageItem(packageId) {
      this.$routerGo(this, "push", {
        path: "/homePage/package/packageDetail",
        query: { combosId: packageId }
      });
    },
    clickExaminationItem(examinationNo) {
      this.$routerGo(this, "push", {
        path: "/homePage/examination/examinationDetail",
        query: { ExaminationNo: examinationNo }
      });
    },
    clickTrainItem(subId) {
      this.$routerGo(this, "push", {
        path: "/homePage/camp/campDetail",
        query: {
          campId: subId,
          ckFrom: global.ckFrom.camp
        }
      });
    },
    getRelatePackage(tabType) {
      if (!this.belongLoading) {
        this.belongLoading = true;
        let $this = this;
        // if (tabType == 2) {+ '&page=' + this.pagePackage + '&limit=10' + '&tabType=' + tabType
          let getUrl = `${global.apiurl}common/saleTogetherList`;
          utilJs.getMethod(getUrl + "?prodId=" + $this.testId + '&prodType=' + global.ckFrom.testpPaper, function (res) {
            $this.belongLoading = false;
            $this.packageList = res
            // if ($this.pagePackage == 1) { //从课程刚进来页面的时候需要获取专栏列表，第二页开始不需要了
            //   $this.packageList = res.list.combos.data;
            // }
            // $this.pagePackage = res.list.combos.current_page < res.list.combos.last_page ? ($this.pagePackage + 1) : $this.pagePackage;
            // $this.is_page_package = res.list.combos.current_page < res.list.combos.last_page ? true : false;
          }, failRes => {
            $this.belongLoading = false;
          });
        // }
      }
    },
    getExamList() {
      let $this = this;
      if (!this.belongEximLoading) {
        utilJs.getMethod(`${global.apiurl}paper/relateTopicList/` + $this.testId + '?page=' + this.pageExim + '&limit=10', function (res) {
          $this.belongEximLoading = false;
          $this.examList = $this.examList.concat(res.data);
          if ($this.pageExim == 1) {
              $this.examList = res.data;
            } else {
              $this.examList = [...$this.examList, ...res.data];
            }
            if (res.data && (res.data.length < 10)) {
              $this.dataStatus = $this.pageExim == 1 && res.data.length == 0 ? 'NO_DATA' : 'NO_MORE_DATA';
            } else {
              $this.dataStatus = 'HAS_MORE_DATA';
              $this.pageExim++;
            }
            $this.belongEximLoading = false;
        }, failRes => {
          $this.belongEximLoading = false;
        });
      }
    },
    getTrainList() {
      let $this = this;
      if (!this.belongTrainLoading) {
        utilJs.getMethod(`${global.apiurl}paper/relateTrainList/` + $this.testId + '?page=' + this.pageTrain + '&limit=10&prodType=' + global.ckFrom.testpPaper, function (res) {
          $this.belongTrainLoading = false;
          $this.TrainList = $this.TrainList.concat(res.data);
          if ($this.pageTrain == 1) {
              $this.TrainList = res.data;
            } else {
              $this.TrainList = [...$this.TrainList, ...res.data];
            }
            if (res.data && (res.data.length < 10)) {
              $this.trainDataStatus = $this.pageTrain == 1 && res.data.length == 0 ? 'NO_DATA' : 'NO_MORE_DATA';
            } else {
              $this.trainDataStatus = 'HAS_MORE_DATA';
              $this.pageTrain++;
            }
            $this.belongTrainLoading = false;
        }, failRes => {
          $this.belongTrainLoading = false;
        });
      }
    },
    getRelateCourseList() {
      let $this = this;
      if (!this.CourseListLoading) {
        utilJs.getMethod(`${global.apiurl}paper/relateCourseList/` + $this.testId + '?page=' + this.pageCourse + '&limit=10&prodType=' + global.ckFrom.testpPaper, function (res) {
          $this.CourseListLoading = false;
          $this.CourseList = $this.CourseList.concat(res.data);
          if ($this.pageCourse == 1) {
              $this.CourseList = res.data;
            } else {
              $this.CourseList = [...$this.CourseList, ...res.data];
            }
            if (res.data && (res.data.length < 10)) {
              $this.CourseListStatus = $this.pageCourse == 1 && res.data.length == 0 ? 'NO_DATA' : 'NO_MORE_DATA';
            } else {
              $this.CourseListStatus = 'HAS_MORE_DATA';
              $this.pageCourse++;
            }
            $this.CourseListLoading = false;
        }, failRes => {
          $this.CourseListLoading = false;
        });
      }
    },
    getRelateColumnList() {
      let $this = this;
      if (!this.ColumnListLoading) {
        utilJs.getMethod(`${global.apiurl}paper/relateColumnList/` + $this.testId + '?page=' + this.pageCourse + '&limit=10&prodType=' + global.ckFrom.testpPaper, function (res) {
          $this.ColumnListLoading = false;
          $this.ColumnList = $this.ColumnList.concat(res.data);
          if ($this.pageCourse == 1) {
              $this.ColumnList = res.data;
            } else {
              $this.ColumnList = [...$this.ColumnList, ...res.data];
            }
            if (res.data && (res.data.length < 10)) {
              $this.ColumnListStatus = $this.pageCourse == 1 && res.data.length == 0 ? 'NO_DATA' : 'NO_MORE_DATA';
            } else {
              $this.ColumnListStatus = 'HAS_MORE_DATA';
              $this.pageCourse++;
            }
            $this.ColumnListLoading = false;
        }, failRes => {
          $this.ColumnListLoading = false;
        });
      }
    },
    closeCombo: function () {
      this.showCombo = false;
    },
    //提交密码
    submitPassword(inputPwd) {
      if (!inputPwd.trim()) {
        this.noticeText = "*密码错误";
        return;
      }
      if (isClick) {
        return;
      }
      isClick = true;
      utilJs.postMethod(global.apiurl + "paper/passwordJoin", {
        password: inputPwd,
        type: 2,
        prodId: this.testId
      }, res => {
        isClick = false;
        if (res.code == 500) {
          this.noticeText = "*密码错误";
        } else if (res.code == 200) {
          this.showPassword = false;
          this.testInfo.permission = true
          this.goTest()
        }
      },
        failRes => {
          isClick = false;
        }
      );
    },
    changePsw() {
      this.noticeText = "";
    },
    inputPsw() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.passwordBind) {
        if (utilJs.goBindMobile()) return;
      }
      // 有关联表单，则跳到报名表单处
      if (this.testInfo.collectPage != 3 && this.testInfo.isRelForm == true && this.testInfo.hasFormLog == false && localStorage.getItem("showForm") == 1) {
        this.goForm()
        return;
      }
      this.noticeText = "";
      this.showPassword = true;
    },
    clickDesc(e) {
      if (e.target.tagName == 'IMG' && e.target.src) {
        wxUtilJs.previewImage({
          current: e.target.src, // 当前显示图片的http链接
          urls: [e.target.src] // 需要预览的图片http链接列表
        });
      }
    },
    goAnswerResult() {
      this.$routerGo(this, "push", {
        path: "/homePage/examination/examinationResult",
        query: {
          paperMainId: this.testInfo.paperMainId,
        }
      });
    },
    goTest() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.getBind) {
        if (utilJs.goBindMobile()) return;
      }
      if (this.testInfo.collectPage != 3 && this.testInfo.isRelForm == true && this.testInfo.hasFormLog == false && localStorage.getItem("showForm") == 1) {
        this.goForm();
        return;
      }
      let nt = (new Date()).getTime();
      let lt = utilJs.getTimeByDate(this.testInfo.lastJoinTime);
      if ((this.testInfo.intervalTime != 0) && (lt + this.testInfo.intervalTime * 60 * 1000 > nt)) {
        let interval = lt + (this.testInfo.intervalTime * 60 * 1000) - nt;
        let secondTime = parseInt(interval / 1000);
        let minuteTime = 0;
        if (secondTime > 60) {
          minuteTime = parseInt(secondTime / 60);
          secondTime = parseInt(secondTime % 60);
        }
        let showTime = minuteTime > 0 ? (minuteTime + '分' + secondTime + '秒') : (secondTime + '秒')
        this.$showCjToast({
          text: '请在' + showTime + '后重测',
          type: "text",
        });
        return
      }
      let $this = this;
      if ($this.testInfo.enableDayPractice == 1 && $this.testInfo.restart == 1) {
        utilJs.getMethod(global.apiurl + 'paper/judgeEntry/' + $this.testId, function (res) {
          if (res.status == 1) {
              let reStart = 2
              if ($this.testInfo.enableResurvey == 1 && $this.testInfo.finishedTestInfo) {
                reStart = 1
              }
              utilJs.postMethod(global.apiurl + "paperLibrary/createExam", {
                paperMainId: $this.testInfo.paperMainId,
                ckFrom:reStart,
                entryProdType:1,
                prodId:$this.testId
              }, res => {
                $this.$routerGo($this, "push", {
                  path: "/homePage/examination/examinationAnswer",
                  query: {
                    paperMainId: $this.testInfo.paperMainId,
                    goOnNum: 1,
                    ttId: $this.ttId,
                    tpId: $this.tpId,
                    tlId: $this.tlId,
                    progress: $this.progress,
                  }
                });
              })
          } else {
            $this.$showCjToast({
              text: res.msg + '</br>' + res.showTime,
              type: 'warn'
            });
          }
        })
      } else {
      // 0未考试 1考试进行一半 2已经完成考试
        if ($this.testInfo.hasStart == 2) {
          $this.$routerGo($this, "push", {
            path: "/homePage/examination/examinationResult",
            query: {
              paperMainId: $this.testInfo.paperMainId,
              ttId: $this.ttId,
              tpId: $this.tpId,
              tlId: $this.tlId,
              progress: 100,
            }
          });
        } else if ($this.testInfo.hasStart == 1) {
          if ($this.testInfo.hasAns == 0) {
            $this.$showCjToast({
              text: "该考试暂无题目，请联系管理员",
              type: 'warn',
            });
          } else {
            utilJs.getMethod(global.apiurl + 'paper/judgeEntry/' + $this.testId, function (res) {
              if (res.status == 1) {
                $this.$routerGo($this, "push", {
                  path: "/homePage/examination/examinationAnswer",
                  query: {
                    paperMainId: $this.testInfo.paperMainId,
                    goOnNum: $this.testInfo.goNum,
                    ttId: $this.ttId,
                    tpId: $this.tpId,
                    tlId: $this.tlId,
                    progress: $this.progress,
                  }
                })
              } else {
                $this.$showCjToast({
                  text: res.msg + '</br>' + res.showTime,
                  type: 'warn'
                });
              }
            })
          }
        } else {
          if ($this.testInfo.hasAns == 0) {
            $this.$showCjToast({
              text: "该考试暂无题目，请联系管理员",
              type: 'warn',
            });
          } else {
            utilJs.getMethod(global.apiurl + 'paper/judgeEntry/' + $this.testId, function (res) {
              if (res.status == 1) {
                let reStart = 2
                if ($this.testInfo.enableResurvey == 1 && $this.testInfo.finishedTestInfo) {
                  reStart = 1
                }
                utilJs.postMethod(global.apiurl + "paperLibrary/createExam", {
                  paperMainId: $this.testInfo.paperMainId,
                  ckFrom:reStart,
                  entryProdType:1,
                  prodId:$this.testId
                }, res => {
                  $this.$routerGo($this, "push", {
                    path: "/homePage/examination/examinationAnswer",
                    query: {
                      paperMainId: $this.testInfo.paperMainId,
                      goOnNum: 1,
                      ttId: $this.ttId,
                      tpId: $this.tpId,
                      tlId: $this.tlId,
                      progress: $this.progress,
                    }
                  });
                })
              } else {
                  $this.$showCjToast({
                    text: res.msg + '</br>' + res.showTime,
                    type: 'warn'
                  });
                }
              })
          }
        }
      }
    },
    closeModal() {
      this.showCoupon = false;
    },
    //获取可以领取的优惠券
    getCouponList: function () {
      if (!this.couponLoading) {
        this.couponLoading = true;
        let $this = this;
        utilJs.getMethod(global.apiurl + 'redeemCodes/getCouponsByRedeemType?courseId=' + $this.testId + '&redeemType=140&limit=10&page=' + this.couponPage, function (res) {
          $this.couponLoading = false;
          $this.couponList = $this.couponList.concat(res.data);
          $this.couponPage = res.next_page_url ? ($this.couponPage + 1) : $this.couponPage;
          $this.couponIsPage = res.next_page_url ? true : false;
        },
          failRes => {
            $this.couponLoading = false;
          }
        );
      }
    },
    //邀请好友
    spreadInvite() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.shareBind) {
        if (utilJs.goBindMobile()) return;
      }
      if (this.testInfo.isInvitionCard == 0) {
        this.isShowShare = true;
        return;
      }
      let extId = this.$route.query.testId;
      this.$routerGo(this, "push", {
        path: "/homePage/spread/spreadCustom",
        query: {
          ckFrom: global.ckFrom.testpPaper,
          cId: 0,
          extId: extId
        }
      })
    },
    //回退到上级(知识套餐),不支持单独售卖
    backPackage: function () {
      if (pathFrom == "/homePage/column/columnDetail" || pathFrom == "/homePage/package/packageDetail") {
        this.$router.go(-1);
      } else {
        this.$routerGo(this, "push", {
          path: "/homePage/package/packageList",
          query: { noHighL: true, 'showAll': true, 'proType': 8, "proId": this.testId }
        });
      }
    },
    //助力详情
    goHelpDetail: function () {
      if (this.bindPhoneSetting && this.bindPhoneSetting.helpBind && utilJs.goBindMobile()) {
        return
      }
      if (this.faStatus == 1) {
        this.$showCjToast({
          text: '活动未开始，暂不能助力领取！',
          type: 'warn'
        });
      } else {
        this.$routerGo(this, "push", {
          path: "/homePage/task/task",
          query: { 'faId': this.testInfo.faId, 'refereeId': localStorage.getItem("userId") }
        });
      }
    },
    //活动海报
    invitePoster: function () {
    if (this.bindPhoneSetting && this.bindPhoneSetting.shareBind) {
        if (utilJs.goBindMobile()) return;
      }
      let ckFrom = global.ckFrom.testpPaper;//this.ckFrom;
      let type = this.testInfo.collage ? 3 : this.testInfo.sales ? 2 : 4;
      let cId = this.testInfo.isFriendHelper ? this.testInfo.faId : this.testInfo.collage ? this.testInfo.collage.collageId : this.testInfo.sales.pId;
      let proId = this.testId;
      this.$routerGo(this, "push", { path: '/homePage/spread/spreadPoster', query: { cId: cId, type: type, ckFrom: ckFrom, proId: proId } });
    },
    //跳转至大转盘
    goTOturn() {
      let $this = this
      $this.$routerGo($this, "push", {
        path: "/homePage/marketing/turntable",
        query: {
          taId: $this.testInfo.joinActivityInfo.activityData.id
        }
      });
    },
    //获取详情
    getTestDetail() {
      let $this = this
      let postUrl = global.apiurl + "paper/detail/" + $this.testId + '?isSkeleton=1';
      if (this.themeId) {
        postUrl = postUrl + `&themeId=${this.themeId}`
      }
      utilJs.getMethod(postUrl,
        res => {
          if (res.isGrounding == 0) {
            this.$routerGo(this, "replace", {
              path: "/error/emptyPage",
              query: {
                info: "很抱歉，该考试不存在"
              }
            });
          }
          if ((res.price * 1 > 0 && res.isGrounding == -1 && !res.permission) || (res.price * 1 == 0 && res.isGrounding == -1)) {
            this.$routerGo(this, "replace", {
              path: "/error/emptyPage",
              query: {
                info: '很抱歉，该考试已下架'
              }
            })
          }
          if (res.sales != null && (res.sales.limit == 0 || res.sales.balance > 0) && res.sales.status && this.companyAuth.enableFlashSalesModule == 1) { // 限时购
            let nt = (new Date()).getTime();
            let st = utilJs.getTimeByDate(res.sales.sales.startTime);
            let et = utilJs.getTimeByDate(res.sales.sales.endTime);
            if (nt >= st && nt < et && res.sales.sales.status > -1) {
              res.sales.sales.status = 2;
            } else if (nt < st && res.sales.sales.status == 1) {
              res.sales.sales.status = 1;
            } else if (nt >= et && res.sales.sales.status == 2) {
              res.sales.sales.status = -1;
              res.sales = null;
            } else {
              res.sales = null;
            }
          } else {
            res.collage = null;
            res.sales = null;
          }
          if (res.combos.length > 0) {
            for (let i in res.combos) {
              res.combos[i].ttId = res.combos[i].id
            }
          }
          this.testInfo = res
          // optimalPriceType：1 产品本身价格 2 vip价格 3 svip价格 4 服务商 101 限时购 102 拼团 112 砍价  10 链动会员 20 链动代理商 99 链动复购
          this.optimal = res.optimal || null;
          if ($this.testInfo.joinActivityInfo && $this.testInfo.joinActivityInfo.isShowDialog == 1) {
            $this.$cjConfirm({
              title: '', //
              titleCenter: true, //标题是否居中
              message: '恭喜！您获得了大转盘抽奖机会！',
              messageCenter: true, //内容是否居中
              showMasker: true, //是否显示透明背景
              clickCloseModal: false, //是否点击透明背景关闭弹窗
              showCancelButton: true, //是否显示取消按钮
              cancelButtonText: '稍后再说', //取消按钮文本
              confirmButtonText: '立刻前往', //确认按钮文本
              onConfirm() {
                $this.$routerGo($this, "push", {
                  path: "/homePage/marketing/turntable",
                  query: {
                    taId: $this.testInfo.joinActivityInfo.activityData.id
                  }
                });
              }
            })
          }
          this.wechatShare();
          this.getRelatePackage(2);
          this.getExamList()
          this.getTrainList()
          this.getRelateCourseList()
          this.getRelateColumnList()
          if (res.sales && res.sales.sales) {
            this.isSalesBegin = (res.sales.sales.startTime).replace(/\s+|[-]|[:]/g, "") <= (utilJs.getNowTime()).replace(/\s+|[-]|[:]/g, "") ? true : false;
          }
        }
      );
    },
    //表单
    goForm() {
      let isGoBack = (this.testInfo.isSaleAlone == -1 && this.testInfo.isSaleTogether == 1) || this.testInfo.permission || this.testInfo.payType == 3 || (this.isMarketing && !this.testInfo.sales) || this.testInfo.isSaleOnly == 0 ? 1 : 0;
      let queryT = null;
      let pId = this.testInfo.sales ? this.testInfo.sales.pId : null;
      queryT = {
        extId: this.testInfo.paperMainId,
        ckFrom: global.ckFrom.testpPaper,
        isFromInvite: 0,
        cId: -1,
        pId: pId,
        isGoBack: isGoBack,
        type: 1,
        relType: 11
      }
      this.$routerGo(this, "push", { path: '/homePage/form', query: queryT });
    },
    // 营销活动倒计时
    falshSalesTime(status) {
      if (this.testInfo.sales) {
        this.testInfo.sales.sales.status = status
      } else if (this.testInfo.collage) {
        this.testInfo.collage.status = status
      } else if (this.testInfo.isFriendHelper) {
        this.faStatus = status;
      }
    },
    // 营销活动倒计时结束
    finishFlashSales(status) {
      if (this.testInfo.sales) {
        this.testInfo.sales.sales.status = status;
      } else if (this.testInfo.collage) {
        this.testInfo.collage.status = status
      } else if (this.testInfo.isFriendHelper) {
        this.faStatus = status;
      }
      // 活动已结束，清空所有营销活动信息及状态
      if (status == -1) {
        this.testInfo.sales = null;
        this.testInfo.collage = null;
        this.testInfo.isFriendHelper = false;
      }
    },
    //点击立即购买
    clickBuy() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.buyBind) {
        if (utilJs.goBindMobile()) return;
      }
      if (this.testInfo.isSaleAlone == 1) {
        if (this.testInfo.collectPage == 1 && this.testInfo.collectPage != 3 && this.testInfo.isRelForm == true && this.testInfo.hasFormLog == false && localStorage.getItem("showForm") == 1) {
          this.goForm();
          return;
        }
        let queryT = null;
        queryT = {
          extId: this.testInfo.paperMainId,
          ckFrom: global.ckFrom.testpPaper,
          isFromInvite: 0,
          pId: this.testInfo.sales && this.testInfo.sales.sales.status == 2 && this.optimal && this.optimal.optimalPriceType == 101 ? this.testInfo.sales.pId : '',
          cId: -1,
        }
        this.$routerGo(this, "push", {
          path: "/homePage/course/coursePay",
          query: queryT
        });
      } else {
        this.$showCjToast({
          text: "该考试不支持单卖",
          type: 'warn',
        });
      }
    },
    wechatShare: function () {
      let title = this.testInfo.shareTitle;
      let shareImg = this.testInfo.sales ? this.testInfo.sales.shareImg : this.testInfo.sharePic;
      if (this.testInfo.collage != null && (this.testInfo.collage.status == 2 || this.testInfo.collage.status == 1)) {
        title = `【邀您一起拼团】${title}`;
      }
      if (this.testInfo.sales) {
        title = `【限时抢购】${title}`;
      }
      let shareUrl =
        window.location.href.split("#")[0] +
        "#/homePage/testPaper/testDetail?testId=" +
        this.testId + "&refereeId=" +
        localStorage.getItem("userId");
      let shareDesc = this.testInfo.shareDesc || "点击查看详情";
      utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function () {});
    },
    //手机端分享
    appShare: function () {
      var title = this.testInfo.shareTitle;
      var shareImg = this.testInfo.sales ? this.testInfo.sales.shareImg : this.testInfo.sharePic;
      if (this.testInfo.collage != null && (this.testInfo.collage.status == 2 || this.testInfo.collage.status == 1)) {
        title = `【邀您一起拼团】${title}`;
      }
      if (this.testInfo.sales) {
        title = `【限时抢购】${title}`;
      }
      var shareUrl =
        window.location.href.split("#")[0] +
        "#/homePage/testPaper/testDetail?testId=" +
        this.testId + "&refereeId=" +
        localStorage.getItem("userId");
      var shareDesc = this.testInfo.shareDesc || "点击查看详情";
      utilJs.appShareTrue(title, shareImg, shareUrl, shareDesc);
    },
  },
  activated() {
    setDocumentTitle("考试详情"); // eslint-disable-line
    this.testId = this.$route.query.testId;
    this.ttId = this.$route.query.ttId || "";
    this.tpId = this.$route.query.tpId || ""; //环节id
    this.tlId = this.$route.query.tlId || "";
    this.themeId = this.$route.query.themeId || '';
    this.progress = this.$route.query.progress || "";
    this.origin = this.$route.query.origin || '';
    this.prodId = this.$route.query.prodId || '';
    this.isiOS = navigator.userAgent.indexOf("IOSLogin") > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf("IOSNewApp") > -1;
    this.testInfo = {
      combos:[]
    };
    this.faStatus = 1;
    this.couponList = [];
    this.couponPage = 1;
    this.couponLoading = false;
    this.couponIsPage = false;
    this.showCombo = false;
    this.optimal = null;
    getBindPhoneSetting(global.ckFrom.testpPaper).then(res => {
      this.bindPhoneSetting = res;
    });
    this.getTestDetail();
    this.getCouponList();
    this.originModal();
  },
  deactivated() {
  }
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only  -->
<style scoped>
.tinymce-text{
  color: #666;
}
.tinymce-text >>> a > img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
.prodType-triangle {
  width: 0;
  height: 0;
  border-width: 0.2rem 0.2rem 0 0.2rem;
  border-style: solid;
  border-color: transparent #fff transparent transparent;
  bottom: 0;
  right: 0;
}
.closeBig >>> p > img,
.closeBig >>> section > img,
.closeBig >>> div > img,
.closeBig >>> img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
.aCloseBig >>> p > a > img,
.aCloseBig >>> section > a > img,
.aCloseBig >>> div > a > img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
.c-line{
  width: .05rem;
  height: 0.7rem;
  background: #d8d8d8;
}
</style>
